import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import '/base/view.dart';
import 'logic.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '/Routes.dart';

class MyPage extends StatelessWidget {
  final logic = Get.put(MyLogic());
  final state = Get.find<MyLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        getTitle(),
        Expanded(
            child: ListView(
              padding: EdgeInsets.all(16.w),
              children: [
                getUserHead(),
                SizedBox(
                  height: 16.w,
                ),
                getPhoneNum(),
                SizedBox(
                  height: 16.w,
                ),
                getAppUpdate(),
                SizedBox(
                  height: 16.w,
                ),
                getOutLogin(),
              ],
            )),
      ],
    );
  }

  /**
   * 标题
   */
  Widget getTitle() {
    return Container(
      width: double.infinity,
      height: 66.w,
      color: Colors.white,
      padding: EdgeInsets.only(bottom: 9.w),
      alignment: Alignment.bottomCenter,
      child: Text(
        "个人中心",
        style: TextStyle(color: Color(0xFF333333), fontSize: 18.w),
      ),
    );
  }

  /**
   * 用户头像
   */
  Widget getUserHead() {
    return Container(
      width: double.infinity,
      height: 93.w,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: Row(
        children: [
          SizedBox(
            width: 16.w,
          ),
          ClipOval(
            child: Image.network(
              "https://tva1.sinaimg.cn/large/006y8mN6gy1g7aa03bmfpj3069069mx8.jpg",
              width: 60.w,
              height: 60.w,
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            width: 20.w,
          ),
          Expanded(
              child: Text(
                "SciOne 嘻嘻嘻",
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: 20.w, color: Color(0xFF333333)),
              )),
          SizedBox(
            width: 20.w,
          ),
        ],
      ),
    );
  }

  /**
   * 手机号
   */
  Widget getPhoneNum() {
    return Container(
      width: double.infinity,
      height: 64.w,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: Row(
        children: [
          SizedBox(
            width: 15.w,
          ),
          Image.asset(
            "images/my/phone_num.png",
            fit: BoxFit.cover,
            width: 28.w,
            height: 28.w,
          ),
          SizedBox(
            width: 8.w,
          ),
          Text(
            "手机号",
            style: TextStyle(color: Color(0xFF333333), fontSize: 16.w),
          ),
          Expanded(
              child: Text(
                "1888888",
                maxLines: 1,
                textAlign: TextAlign.right,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: 16.w, color: Color(0xFF999999)),
              )),
          SizedBox(
            width: 20.w,
          ),
        ],
      ),
    );
  }

  /**
   * 版本更新
   */
  Widget getAppUpdate() {
    return Container(
        width: double.infinity,
        height: 64.w,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
        child: InkWell(
          child: Row(
            children: [
              SizedBox(
                width: 15.w,
              ),
              Image.asset(
                "images/my/app_update.png",
                fit: BoxFit.cover,
                width: 28.w,
                height: 28.w,
              ),
              SizedBox(
                width: 8.w,
              ),
              Text(
                "检查更新",
                style: TextStyle(color: Color(0xFF333333), fontSize: 16.w),
              ),
              Expanded(
                  child: Align(
                      alignment: Alignment.centerRight,
                      child: Image.asset(
                        "images/ic_next.png",
                        width: 20.w,
                        height: 20.w,
                      ))),
              SizedBox(
                width: 20.w,
              ),
            ],
          ),
          onTap: () {
            SmartDialog.showToast('test toast');
          },
        )

    );
  }

  /**
   * 退出登录
   */
  Widget getOutLogin() {
    return Container(
      height: 54.w,
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: TextButton(
        child: Text(
          "退出登录",
          style: TextStyle(fontSize: 16.w, color: const Color(0xFFEE5555)),
        ),
        onPressed: () {
          Get.offAllNamed(Routes.routeInitial);
        },
      ),
    );
  }
}

